<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header">
                <span>会议现场互动</span>
            </h3>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-sm-12">
            <section class="panel">
                <div class="panel-body" id="live_body">
                    <?php foreach($live as $val){
                    if($val == 1){
                        echo '<div style="float:left;margin-left: 30px;width: 20%;height: 200px; border: 2px solid black;" data-div-type="1">
                            <div style="font-size:20px;margin-top: 20%;width: 75%;height:50px;text-align: center;border: 1px solid black;line-height: 50px;">抽奖</div>
                            <div style="margin-top: 30px;margin-left: 35%;">
                                <a href="/User/Meeting/lucky_index?meetId=' . I("get.meetId", "", "") . '"><div style="width: 50px;height: 50px;border-radius: 25px;border: 1px solid black;text-align: center;line-height: 50px;position:absolute">编辑</div></a>
                                <div style="border-radius: 25px;border: 1px solid black;width: 50px;height: 50px;text-align: center;line-height: 50px;position: relative;left: 60px;" onclick="live_delete(1)">删除</div>
                            </div>
                            </div>';
                        }
                        if($val == 2){
                            echo '<div style="float:left;margin-left: 30px;width: 20%;height: 200px; border: 2px solid black;" data-div-type="2">
                                <div style="font-size:20px;margin-top: 20%;width: 75%;height:50px;text-align: center;border: 1px solid black;line-height: 50px;">签到上墙</div>
                                <div style="margin-top: 30px;margin-left: 35%;">
                                    <a href="/User/Meeting/sign_index?meetId=' . I("get.meetId", "", "") . '"><div style="width: 50px;height: 50px;border-radius: 25px;border: 1px solid black;text-align: center;line-height: 50px;position:absolute">编辑</div></a>
                                    <div style="border-radius: 25px;border: 1px solid black;width: 50px;height: 50px;text-align: center;line-height: 50px;position: relative;left: 60px;" onclick="live_delete(2)">删除</div>
                                </div>
                            </div>';
                        }
                    }?>
                    <div style="float:left;margin-left: 30px;width: 20%;height: 200px; border: 2px solid black;text-align: center;" onclick="display();">
                        <div style="font-size: 100px;line-height: 200px;">+</div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-keyboard="false" style="margin-top: 20%">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div id="live_add_content">
                    <?php
                    if(!in_array(1, $live)){
                        echo '<button class="btn" onclick="live_add(1);" data-lucky-type="1" style="margin-left:20px;">抽奖</button>';
                        }
                        if(!in_array(2, $live)){
                            echo '<button class="btn" onclick="live_add(2);" data-lucky-type="2" style="margin-left:20px;">现场签到</button>';
                        }
                    ?>
                </div>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
    $(".need").each(function(){
        $(this).prepend("<span style='color:red'>*</span>");
    });
    function display(){
        $("#myModal").modal("show");
    }
    var meetId = <?php echo I("get.meetId", -1, "")?>;
    function live_add(type){
        $.ajax({
           data:{
               live: type,
               meetId: meetId
           },
            dataType:'json',
            type:'get',
            url:"/User/Meeting/live_add",
            success:function(res){
                $("#myModal").modal("hide");
                if(type == 1){
                    $("#live_body").prepend('<div style="float:left;margin-left: 30px;width: 20%;height: 200px; border: 2px solid black;" data-div-type="1"> ' +
                        '<div style="font-size:20px;margin-top: 20%;width: 75%;height:50px;text-align: center;border: 1px solid black;line-height: 50px;">抽奖</div>' +
                        '<div style="margin-top: 30px;margin-left: 35%;">' +
                        '<a href="/User/Meeting/lucky_index?meetId=' + meetId + '"><div style="width: 50px;height: 50px;border-radius: 25px;border: 1px solid black;text-align: center;line-height: 50px;position:absolute">编辑</div></a>' +
                        '<div style="border-radius: 25px;border: 1px solid black;width: 50px;height: 50px;text-align: center;line-height: 50px;position: relative;left: 60px;" onclick="live_delete(1)">删除</div>' +
                        '</div></div>');
                }
                if(type == 2){
                    $("#live_body").prepend('<div style="float:left;margin-left: 30px;width: 20%;height: 200px; border: 2px solid black;" data-div-type="2">' +
                        '<div style="font-size:20px;margin-top: 20%;width: 75%;height:50px;text-align: center;border: 1px solid black;line-height: 50px;">签到上墙</div>' +
                        '<div style="margin-top: 30px;margin-left: 35%;">' +
                        '<a href="/User/Meeting/sign_index?meetId=' + meetId + '"><div style="width: 50px;height: 50px;border-radius: 25px;border: 1px solid black;text-align: center;line-height: 50px;position:absolute">编辑</div></a>' +
                        '<div style="border-radius: 25px;border: 1px solid black;width: 50px;height: 50px;text-align: center;line-height: 50px;position: relative;left: 60px;" onclick="live_delete(2)">删除</div>' +
                        '</div></div>');
                }
                var obj_str = "button[data-lucky-type=" + type + "]";
                $(obj_str).remove();
            }
        });
    }
    function live_delete(type){
        $.ajax({
            data:{
                live: type,
                meetId: meetId
            },
            dataType:'json',
            type:'get',
            url:"/User/Meeting/live_delete",
            success:function(res){
                var obj_str = "div[data-div-type=" + type + "]";
                $(obj_str).remove();
                if(type == 1){
                    $("#live_add_content").append('<button class="btn" onclick="live_add(1);" data-lucky-type="1" style="margin-left:20px;">抽奖</button>');
                }
                if(type == 2){
                    $("#live_add_content").append('<button class="btn" onclick="live_add(2);" data-lucky-type="2" style="margin-left:20px;">现场签到</button>');
                }
            }
        });
    }
</script>
